package org.mikrosopht.movievote.client;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;


public class MovieListPruner extends Composite implements ClickListener {
  private CheckBox screenings = new CheckBox("Show only my screenings");
  private CheckBox unrated = new CheckBox("Show only unrated");
  private HorizontalPanel panel = new HorizontalPanel();
  private MovieListPrunerEventReceiver receiver;

  public MovieListPruner(MovieListPrunerEventReceiver receiver) {
    this.receiver = receiver;
    screenings.addClickListener(this);
    unrated.addClickListener(this);
    panel.add(screenings);
    panel.add(unrated);
    initWidget(panel);
  }

  public void onClick(Widget sender) {
    boolean checked = false;
    if (sender == screenings) {
      checked = screenings.isChecked();
      if (checked) {
        unrated.setValue(!checked);
      }
      receiver.onScreeningsClick(checked);
    } else if (sender == unrated) {
      checked = unrated.isChecked();
      if (checked) {
        screenings.setValue(!checked);
      }
      receiver.onUnratedClick(checked);
    }
  }

  public void setScreeningsChecked(boolean value) {
    screenings.setValue(value);
  }

  public void setUnratedChecked(boolean value) {
    unrated.setValue(value);
  }
}
